//
//  PriceSelectView.m
//  beautyAccompany
//
//  Created by xiaocankeji on 15/11/26.
//  Copyright © 2015年 xiaocankeji. All rights reserved.
//

#import "PriceSelectView.h"
#import "PriceTitleView.h"
#define kLineHeight 3
@interface PriceSelectView ()
@property (nonatomic, strong)UIView *selectView;
@property (nonatomic, strong)PriceTitleView *commonView;
@property (nonatomic, strong)PriceTitleView *seniorView;
@property (nonatomic, strong)UIView *lineView;
@end

@implementation PriceSelectView
- (instancetype)init
{
    self = [super init];
    if (self) {
        _selectView = [[UIView alloc] init];
        _selectView.backgroundColor = [UIColor whiteColor];
        _selectView.layer.borderWidth = 0.5;
        _selectView.layer.borderColor = RGBA(200, 200, 200, 1).CGColor;
        [self addSubview:_selectView];
        
        _commonView = [[PriceTitleView alloc] init];
        _commonView.userInteractionEnabled = YES;
        UITapGestureRecognizer *commonTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCommon)];
        [_commonView addGestureRecognizer:commonTap];
        
        [_selectView addSubview:_commonView];
        
        
        _seniorView = [[PriceTitleView alloc] init];
        UITapGestureRecognizer *seniorTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSenior)];
        _seniorView.userInteractionEnabled = YES;
        [_seniorView addGestureRecognizer:seniorTap];
        [_selectView addSubview:_seniorView];
        
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = RGBA(246, 120, 125, 1);
        [_selectView addSubview:_lineView];
        
        
        
    }
    return self;
}
- (void)tapCommon
{
    _selectRight = NO;
    _seniorView.select = NO;
    _commonView.select = YES;
     [Utils animationMobileTimer:0.5 View:_lineView Rect:CGRectMake( 0, _selectView.height - kLineHeight, _selectView.width/2, kLineHeight)];
}
- (void)tapSenior
{
    _selectRight = YES;
    _seniorView.select = YES;
    _commonView.select = NO;
    [Utils animationMobileTimer:0.5 View:_lineView Rect:CGRectMake( _selectView.width/2, _selectView.height - kLineHeight, _selectView.width/2, kLineHeight)];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _selectView.frame = CGRectMake(10, 10, self.width - 20, self.height - 20);
    _commonView.frame = CGRectMake(0, 0, _selectView.width/2, _selectView.height);
    _seniorView.frame = CGRectMake(_selectView.width/2, 0, _selectView.width/2, _selectView.height);
   
    _lineView.frame = CGRectMake(0, _selectView.height - kLineHeight, _selectView.width/2, kLineHeight);
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)setCategory:(MPCategory *)category
{
    _category = category;
    _selectRight = NO;
    _lineView.frame = CGRectMake(0, _selectView.height - kLineHeight, _selectView.width/2, kLineHeight);
    _commonView.title = category.common;
    _commonView.price = [NSString stringWithFormat:@"%ld元/小时",category.commonPrice];
    _commonView.select = YES;
    _seniorView.title = category.senior;
    _seniorView.price = [NSString stringWithFormat:@"%ld元/小时",category.seniorPrice];
    _seniorView.select = NO;
    
}
- (void)setSelectRight:(BOOL)selectRight
{
    _selectRight = selectRight;
    if (selectRight) {
        _seniorView.select = YES;
        _commonView.select = NO;
        
        [Utils animationMobileTimer:0.5 View:_lineView Rect:CGRectMake( _selectView.width/2, _selectView.height - kLineHeight, _selectView.width/2, kLineHeight)];
    }else{
        _seniorView.select = NO;
        _commonView.select = YES;
        [Utils animationMobileTimer:0.5 View:_lineView Rect:CGRectMake( 0, _selectView.height - kLineHeight, _selectView.width/2, kLineHeight)];
    }
    
}
@end
